package FlyGame;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class FlyFrame extends JFrame {
    public int current = 0;
    FlyPanel flyPanel;

    public FlyFrame(int current) throws HeadlessException {
        this.current = current;
        this.setTitle("Fly-Bird 小游戏");
        this.setBounds(100,100,600,500);
        this.setResizable(false);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        flyPanel=new FlyPanel();
        flyPanel.overFrame.overPanel.home.addActionListener(new MyActionListener());

        changeSkin(flyPanel.myBird);
        this.add(flyPanel);

        this.setVisible(true);
        System.out.println(current);
    }

    public void changeSkin(MyBird myBird){
        if(current == 0){
            myBird.birdImage = FlyPicture.Birddown;
            myBird.birdupImage = FlyPicture.Birdup;
        }
        else if(current == 1){
            myBird.birdImage = FlyPicture.Birddown2;
            myBird.birdupImage = FlyPicture.Birdup2;
        }
        else{
            myBird.birdImage = FlyPicture.Birddown3;
            myBird.birdupImage = FlyPicture.Birdup3;
        }
    }

    class MyActionListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            flyPanel.overFrame.dispose();
            dispose();

        }
    }
}
